package com.example.spinning.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.spinning.bean.EndProductQuality;
import com.example.spinning.bean.PaginationResult;
import com.example.spinning.mapper.EndQualityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;


@Service
@Transactional
public class EndQualityService {
    @Autowired
    EndQualityMapper endQualityMapper;


    //增加操作
    public int addNewEndQuality(EndProductQuality endProductQuality) {
        return endQualityMapper.addNewEndQuality(endProductQuality);
    }

    //删除操作
    public boolean deleteEndQualityById(Long[] ids) {
        int result = endQualityMapper.deleteEndQualityById(ids);
        return result == ids.length;
    }

    public PaginationResult<EndProductQuality> findPage(Integer page, Integer size, String batch_no, String name, Date date) {

        QueryWrapper<EndProductQuality> wrapper = new QueryWrapper();
        if (null!=batch_no)
            wrapper.eq("batch_no", batch_no);
        if (null!=name)
            wrapper.eq("name", name);
        if (null!=date)
            wrapper.eq("date", date);

        Page<EndProductQuality> pages = new Page<>(page,size);
        endQualityMapper.selectPage(pages, wrapper);
        int total = endQualityMapper.selectCount(wrapper);
        List<EndProductQuality> list = pages.getRecords();

        PaginationResult<EndProductQuality> pr = new PaginationResult<>();
        pr.setTotal(total);
        pr.setList(list);
        return pr;
    }
    //动态修改
    public int updateCategoryById(EndProductQuality endProductQuality){
        int result = endQualityMapper.updateById(endProductQuality);
        return result;
    }


}

